//
//  UIViewController+MyViewController.m
//  RunTimeDemo
//
//  Created by YYPan on 2018/5/29.
//  Copyright © 2018年 YYPan. All rights reserved.
//

#import "UIViewController+MyViewController.h"
#import <objc/runtime.h>

@implementation UIViewController (MyViewController)

+ (void)load
{
	static dispatch_once_t onceToken;
	dispatch_once(&onceToken, ^{
		Class class = [self class];
		Method originalMethod = class_getInstanceMethod(class, @selector(viewWillAppear:));
		Method myMethod = class_getInstanceMethod(class, @selector(yyp_viewWillAppear:));
		BOOL addMethod = class_addMethod(class, @selector(viewWillAppear:), method_getImplementation(myMethod), method_getTypeEncoding(myMethod));
		if (addMethod) {
			class_replaceMethod(class, @selector(yyp_viewWillAppear:), method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
		} else {
			method_exchangeImplementations(originalMethod, myMethod);
		}
	});
}

- (void)yyp_viewWillAppear:(BOOL)animated
{
	NSLog(@"%@",NSStringFromClass([self class]));
	[self yyp_viewWillAppear:animated];
}

@end
